<template>
    <div class="header">

        <!-- 折叠按钮 -->
        <div class="collapse-btn">
            <i class="el-icon-s-fold"></i>
        </div>
        <div class="logo">卧底大作战</div>
        <div class="header-right">
            <div class="header-user-con">
                <!-- 消息中心 -->
                <!-- 用户头像 -->
                <el-popover v-if="!!$store.state.users_status" placement="right" width="300" trigger="hover">
                    <div style="text-align: right; font-size: 12px;">
                        <el-button type="primary" icon="el-icon-refresh-right" circle @click="GetPerson()" :loading="loadingList"></el-button>
                        <br><br>
                    </div>

                    <el-empty :image-size="200" v-if="!has_room"></el-empty>

                    <el-descriptions v-if="!!has_room" title="" direction="vertical" :column="2" border v-loading="loadingList">
                        <el-descriptions-item label="赛事标题" :span="2">{{ rooms_info.room_title }}</el-descriptions-item>
                        <el-descriptions-item label="类型">
                            <el-tag size="small" v-if="rooms_info.is_password != 1">无锁</el-tag>
                            <el-tag size="small" v-else>密码房</el-tag>
                        </el-descriptions-item>
                        <el-descriptions-item label="赛事大区">{{ rooms_info.room_region }}</el-descriptions-item>
                        <el-descriptions-item label="操作" :span="2">
                            <el-button v-if="!!rooms_info.room_status && rooms_info.room_status != 0" @click="gameRoom(rooms_info)" type="primary" icon="el-icon-caret-left" :style="{width: getWidth('return')}">进入赛事房间</el-button>
                            <el-button  v-if="!!rooms_info.room_status && rooms_info.room_status == 1 && rooms_info.create_id == bakal_player_info.id"  @click="closeRoom(rooms_info)" type="danger" icon="el-icon-error" :style="{width: getWidth('close')}">关闭赛事</el-button>
                        </el-descriptions-item>
                    </el-descriptions>

                    <div class="user-avator"  slot="reference">
                        <img src="@/assets/images/other/jiangui.jpeg" />
                    </div>
                </el-popover>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            loadingList: false,

            has_room: false,
            rooms_info: {},
            bakal_player_info: this.$store.state.bakal_player_info,
        };
    },
    created() {
        if (!!this.$store.state.users_status) {
            this.GetPerson();
        }
    },
    methods: {
        GetPerson() {
            this.playSound('click_one');

            this.loadingList = true;
            this.$post('/api/rooms/person.html', {valid_operate: 'list'}).then(res => {
            	if (res.code == 200) {
                    this.has_room = true;
                    this.rooms_info = res.data;
            	} else {
                    this.has_room = false;
                }
                this.loadingList = false;
            }).catch(err => {
                console.log(err)
                this.loadingList = false;
            });
        },
        gameRoom(items) {
            this.playSound('click_one');
            let routers = {path: '/game-room', query: {
                room_code: items.room_code,
                type: 'return',
            }};
            this.$router.push(routers);
        },
        closeRoom(items) {
            this.playSound('click_one');
        },
        playSound(keyword) {
            this.$parent.playSound(keyword);
        },
        getWidth(key) {
            if (key == 'return') {
                if (this.rooms_info.create_id == this.bakal_player_info.id) {
                    return '48%';
                } else {
                    return "100%";
                }
            } else {
                if (this.rooms_info.create_id == this.bakal_player_info.id && this.rooms_info.room_status == 1) {
                    return '46%';
                } else {
                    return "0%";
                }
            }
        }
    },
};
</script>
<style scoped>
.header {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    height: 70px;
    font-size: 22px;
    color: #fff;
}
.collapse-btn {
    float: left;
    padding: 0 21px;
    cursor: pointer;
    line-height: 70px;
}
.header .logo {
    float: left;
    width: 250px;
    line-height: 70px;
}
.header-right {
    float: right;
    padding-right: 50px;
}
.header-user-con {
    display: flex;
    height: 70px;
    align-items: center;
}
.btn-fullscreen {
    transform: rotate(45deg);
    margin-right: 5px;
    font-size: 24px;
}
.btn-bell,
.btn-fullscreen {
    position: relative;
    width: 30px;
    height: 30px;
    text-align: center;
    border-radius: 15px;
    cursor: pointer;
}
.btn-bell-badge {
    position: absolute;
    right: 0;
    top: -2px;
    width: 8px;
    height: 8px;
    border-radius: 4px;
    background: #f56c6c;
    color: #fff;
}
.btn-bell .el-icon-bell {
    color: #fff;
}
.user-name {
    margin-left: 10px;
}
.user-avator {
    margin-left: 20px;
}
.user-avator img {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
}
.el-dropdown-link {
    color: #fff;
    cursor: pointer;
}
.el-dropdown-menu__item {
    text-align: center;
}
</style>




